<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//用户表
class Finance_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->bbs_article = 'bbs_article';
        $this->bbs_article_category = 'bbs_article_category';
        $this->users_info = 'users_info';
    }
    function listcount($where){
        $this->db->select('*');
        $this->db->from($this->bbs_article);
        $this->db->join($this->bbs_article_category,$this->bbs_article_category.'.id='.$this->bbs_article.'.cat_id',left);
        $this->db->where($where);
        return $this->db->get()->num_rows();
    }
    function lists($where,$page,$limit){
        $this->db->select($this->bbs_article.'.*,'.$this->bbs_article_category.'.name,'.$this->users_info.'.nickname');
        $this->db->from($this->bbs_article);
        $this->db->join($this->bbs_article_category,$this->bbs_article_category.'.id='.$this->bbs_article.'.cat_id',left);
        $this->db->join($this->users_info,$this->users_info.'.user_id='.$this->bbs_article.'.authorid',left);
        $this->db->where($where);
        $this->db->order_by($this->bbs_article.'.create_time','desc');
        $this->db->limit($limit,$page);
        return $this->db->get()->result_array();
    }
    function stick($cat_id){
        $this->db->select($this->bbs_article.'.*,'.$this->bbs_article_category.'.name,'.$this->users_info.'.nickname');
        $this->db->from($this->bbs_article);
        $this->db->join($this->bbs_article_category,$this->bbs_article_category.'.id='.$this->bbs_article.'.cat_id',left);
        $this->db->join($this->users_info,$this->users_info.'.user_id='.$this->bbs_article.'.authorid',left);
        $this->db->where('cat_id',$cat_id);
        $this->db->where('stick',1);
        $this->db->order_by($this->bbs_article.'.create_time','desc');
        $this->db->limit(2,0);
        return $this->db->get()->result_array();
    }
}
